# (C) Datadog, Inc. 2023-present
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)

# Some metrics mapping are too long. This turns off the 120 line limit for this file:
# ruff: noqa: E501

# Karpenter metrics documentation
# https://karpenter.sh/docs/reference/metrics/

METRIC_MAP = {
    'certwatcher_read_certificate': 'certwatcher.read.certificate',
    'certwatcher_read_certificate_errors': 'certwatcher.read.certificate.errors',
    'controller_runtime_active_workers': 'controller.runtime.active_workers',
    'controller_runtime_max_concurrent_reconciles': 'controller.runtime.max.concurrent_reconciles',
    'controller_runtime_reconcile': 'controller.runtime.reconcile',
    'controller_runtime_reconcile_errors': 'controller.runtime.reconcile_errors',
    'controller_runtime_reconcile_time_seconds': 'controller.runtime.reconcile.time_seconds',
    'go_gc_duration_seconds': 'go.gc.duration_seconds',
    'go_goroutines': 'go_goroutines',
    'go_info': 'go_info',
    'go_memstats_alloc_bytes': {'name': 'go.memstats.alloc_bytes', 'type': 'native_dynamic'},
    'go_memstats_buck_hash_sys_bytes': 'go.memstats.buck.hash.sys_bytes',
    'go_memstats_frees': 'go.memstats.frees',
    'go_memstats_gc_sys_bytes': 'go.memstats.gc.sys_bytes',
    'go_memstats_heap_alloc_bytes': 'go.memstats.heap.alloc_bytes',
    'go_memstats_heap_idle_bytes': 'go.memstats.heap.idle_bytes',
    'go_memstats_heap_inuse_bytes': 'go.memstats.heap.inuse_bytes',
    'go_memstats_heap_objects': 'go.memstats.heap.objects',
    'go_memstats_heap_released_bytes': 'go.memstats.heap.released_bytes',
    'go_memstats_heap_sys_bytes': 'go.memstats.heap.sys_bytes',
    'go_memstats_last_gc_time_seconds': 'go.memstats.last.gc.time_seconds',
    'go_memstats_lookups': 'go.memstats.lookups',
    'go_memstats_mallocs': 'go.memstats.mallocs',
    'go_memstats_mcache_inuse_bytes': 'go.memstats.mcache.inuse_bytes',
    'go_memstats_mcache_sys_bytes': 'go.memstats.mcache.sys_bytes',
    'go_memstats_mspan_inuse_bytes': 'go.memstats.mspan.inuse_bytes',
    'go_memstats_mspan_sys_bytes': 'go.memstats.mspan.sys_bytes',
    'go_memstats_next_gc_bytes': 'go.memstats.next.gc_bytes',
    'go_memstats_other_sys_bytes': 'go.memstats.other.sys_bytes',
    'go_memstats_stack_inuse_bytes': 'go.memstats.stack.inuse_bytes',
    'go_memstats_stack_sys_bytes': 'go.memstats.stack.sys_bytes',
    'go_memstats_sys_bytes': 'go.memstats.sys_bytes',
    'go_threads': 'go_threads',
    'karpenter_build_info': 'build_info',
    'karpenter_cloudprovider_batcher_batch_size': 'cloudprovider.batcher.batch_size',
    'karpenter_cloudprovider_batcher_batch_time_seconds': 'cloudprovider.batcher.batch.time_seconds',
    'karpenter_cloudprovider_duration_seconds': 'cloudprovider.duration_seconds',
    'karpenter_cloudprovider_errors': 'cloudprovider.errors',
    'karpenter_cloudprovider_instance_type_cpu_cores': 'cloudprovider.instance.type.cpu_cores',
    'karpenter_cloudprovider_instance_type_memory_bytes': 'cloudprovider.instance.type.memory_bytes',
    'karpenter_cloudprovider_instance_type_offering_available': 'cloudprovider.instance.type.offering_available',
    'karpenter_cloudprovider_instance_type_offering_price_estimate': 'cloudprovider.instance.type.offering_price_estimate',
    'karpenter_cloudprovider_instance_type_price_estimate': 'cloudprovider.instance.type.price_estimate',
    'karpenter_consistency_errors': 'consistency.errors',
    'karpenter_deprovisioning_actions_performed': 'deprovisioning.actions_performed',
    'karpenter_deprovisioning_consolidation_timeouts': 'deprovisioning.consolidation_timeouts',
    'karpenter_deprovisioning_eligible_machines': 'deprovisioning.eligible_machines',
    'karpenter_deprovisioning_evaluation_duration_seconds': 'deprovisioning.evaluation.duration_seconds',
    'karpenter_deprovisioning_replacement_machine_initialized_seconds': 'deprovisioning.replacement.machine.initialized_seconds',
    'karpenter_deprovisioning_replacement_machine_launch_failure_counter': 'deprovisioning.replacement.machine.launch.failure_counter',
    'karpenter_disruption_actions_performed': 'disruption.actions_performed',
    'karpenter_disruption_budgets_allowed_disruptions': 'disruption.budgets.allowed_disruptions',
    'karpenter_disruption_consolidation_timeouts': 'disruption.consolidation_timeouts',
    'karpenter_disruption_eligible_nodes': 'disruption.eligible_nodes',
    'karpenter_disruption_evaluation_duration_seconds': 'disruption.evaluation.duration_seconds',
    'karpenter_disruption_replacement_nodeclaim_failures': 'disruption.replacement.nodeclaim.failures',
    'karpenter_disruption_replacement_nodeclaim_initialized_seconds': 'disruption.replacement.nodeclaim.initialized_seconds',
    'karpenter_disruption_queue_depth': 'disruption.queue_depth',
    'karpenter_disruption_pods_disrupted': 'disruption.pods.disrupted',
    'karpenter_disruption_nodes_disrupted': 'disruption.nodes.disrupted',
    'karpenter_interruption_actions_performed': 'interruption.actions_performed',
    'karpenter_interruption_deleted_messages': 'interruption.deleted_messages',
    'karpenter_interruption_message_latency_time_seconds': 'interruption.message.latency.time_seconds',
    'karpenter_interruption_received_messages': 'interruption.received_messages',
    'karpenter_machines_created': 'machines_created',
    'karpenter_machines_disrupted': 'machines_disrupted',
    'karpenter_machines_drifted': 'machines_drifted',
    'karpenter_machines_initialized': 'machines_initialized',
    'karpenter_machines_launched': 'machines_launched',
    'karpenter_machines_registered': 'machines_registered',
    'karpenter_machines_terminated': 'machines_terminated',
    'karpenter_nodeclaims_created': 'nodeclaims_created',
    'karpenter_nodeclaims_disrupted': 'nodeclaims_disrupted',
    'karpenter_nodeclaims_drifted': 'nodeclaims_drifted',
    'karpenter_nodeclaims_initialized': 'nodeclaims_initialized',
    'karpenter_nodeclaims_launched': 'nodeclaims_launched',
    'karpenter_nodeclaims_registered': 'nodeclaims_registered',
    'karpenter_nodeclaims_terminated': 'nodeclaims_terminated',
    'karpenter_nodepool_limit': 'nodepool_limit',
    'karpenter_nodepool_usage': 'nodepool_usage',
    'karpenter_nodes_allocatable': 'nodes.allocatable',
    'karpenter_nodes_created': 'nodes.created',
    'karpenter_nodes_terminated': 'nodes.terminated',
    'karpenter_nodes_leases_deleted': 'nodes.leases_deleted',
    'karpenter_nodes_system_overhead': 'nodes.system_overhead',
    'karpenter_nodes_termination_time_seconds': 'nodes.termination.time_seconds',
    'karpenter_nodes_total_daemon_limits': 'nodes.total.daemon_limits',
    'karpenter_nodes_total_daemon_requests': 'nodes.total.daemon_requests',
    'karpenter_nodes_total_pod_limits': 'nodes.total.pod_limits',
    'karpenter_nodes_total_pod_requests': 'nodes.total.pod_requests',
    'karpenter_nodes_eviction_queue_depth': 'nodes.eviction.queue_depth',
    'karpenter_pods_startup_time_seconds': 'pods.startup.time_seconds',
    'karpenter_pods_state': 'pods.state',
    'karpenter_provisioner_limit': 'provisioner.limit',
    'karpenter_provisioner_scheduling_duration_seconds': 'provisioner.scheduling.duration_seconds',
    'karpenter_provisioner_scheduling_simulation_duration_seconds': 'provisioner.scheduling.simulation.duration_seconds',
    'karpenter_provisioner_scheduling_queue_depth': 'provisioner.scheduling.queue_depth',
    'karpenter_provisioner_usage': 'provisioner.usage',
    'karpenter_provisioner_usage_pct': 'provisioner.usage.pct',
    'karpenter_cluster_state_synced': 'cluster_state.synced',
    'karpenter_cluster_state_node_count': 'cluster_state.node_count',
    'leader_election_master_status': 'leader_election.master_status',
    'process_cpu_seconds': 'process.cpu_seconds',
    'process_max_fds': 'process.max_fds',
    'process_open_fds': 'process.open_fds',
    'process_resident_memory_bytes': 'process.resident.memory_bytes',
    'process_start_time_seconds': 'process.start.time_seconds',
    'process_virtual_memory_bytes': 'process.virtual.memory_bytes',
    'process_virtual_memory_max_bytes': 'process.virtual.memory.max_bytes',
    'rest_client_requests': 'rest.client_requests',
    'workqueue_adds': 'workqueue_adds',
    'workqueue_depth': 'workqueue_depth',
    'workqueue_longest_running_processor_seconds': 'workqueue.longest.running.processor_seconds',
    'workqueue_queue_duration_seconds': 'workqueue.queue.duration_seconds',
    'workqueue_retries': 'workqueue_retries',
    'workqueue_unfinished_work_seconds': 'workqueue.unfinished.work_seconds',
    'workqueue_work_duration_seconds': 'workqueue.work.duration_seconds',
    # new Karpenter V1 metric names
    'karpenter_nodes_termination_duration_seconds': 'nodes.termination.time_seconds',
    'karpenter_pods_startup_duration_seconds': 'pods.startup.time_seconds',
    'karpenter_voluntary_disruption_queue_failures': 'disruption.replacement.nodeclaim.failures',
    'karpenter_voluntary_disruption_decision_evaluation_duration_seconds': 'disruption.evaluation.duration_seconds',
    'karpenter_voluntary_disruption_eligible_nodes': 'disruption.eligible_nodes',
    'karpenter_voluntary_disruption_consolidation_timeouts': 'disruption.consolidation_timeouts',
    'karpenter_nodepools_allowed_disruptions': 'disruption.budgets.allowed_disruptions',
    'karpenter_voluntary_disruption_decisions': 'disruption.actions_performed',
    'karpenter_scheduler_scheduling_duration_seconds': 'provisioner.scheduling.simulation.duration_seconds',
    'karpenter_scheduler_queue_depth': 'provisioner.scheduling.queue_depth',
    'karpenter_interruption_message_queue_duration_seconds': 'interruption.message.latency.time_seconds',
    'karpenter_nodepools_usage': 'nodepool_usage',
    'karpenter_nodepools_limit': 'nodepool_limit',
}

RENAME_LABELS_MAP = {
    "version": "go_version",
    'host': 'client_host',
}
